home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / gaelco.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  5KB  |  197 lines

  1. #include "driver.h"
  2. #include "vidhrdw/generic.h"
  3. #include "tilemap.h"
  4.  
  5. unsigned char *splash_vregs;
  6. unsigned char *splash_videoram;
  7. unsigned char *splash_spriteram;
  8. unsigned char *splash_pixelram;
  9.  
  10. static struct tilemap *screen0, *screen1;
  11. static struct osd_bitmap *screen2;
  12.  
  13. /***************************************************************************
  14.  
  15.     Palette
  16.  
  17. ***************************************************************************/
  18.  
  19. WRITE_HANDLER( paletteram_xRRRRxGGGGxBBBBx_word_w )
  20. {
  21.     int r,g,b;
  22.     int oldword = READ_WORD(&paletteram[offset]);
  23.     int newword = COMBINE_WORD(oldword,data);
  24.  
  25.     WRITE_WORD(&paletteram[offset],newword);
  26.  
  27.     r = (newword >> 11) & 0x0f;
  28.     g = (newword >>  6) & 0x0f;
  29.     b = (newword >>  1) & 0x0f;
  30.  
  31.     r = (r << 4) | r;
  32.     g = (g << 4) | g;
  33.     b = (b << 4) | b;
  34.  
  35.     palette_change_color(offset >> 1, r, g, b);
  36. }
  37.  
  38. /***************************************************************************
  39.  
  40.     Callbacks for the TileMap code
  41.  
  42. ***************************************************************************/
  43.  
  44. static void get_tile_info_screen0(int tile_index)
  45. {
  46.     unsigned short data = READ_WORD(&splash_videoram[2*tile_index]);
  47.     unsigned char attr = data >> 8;
  48.     unsigned char code = data & 0xff;
  49.  
  50.     SET_TILE_INFO(0, code + ((0x20 + (attr & 0x0f)) << 8), (attr & 0xf0) >> 4);
  51. }
  52.  
  53. static void get_tile_info_screen1(int tile_index)
  54. {
  55.     unsigned short data = READ_WORD(&splash_videoram[2*tile_index+0x1000]);
  56.     unsigned char attr = data >> 8;
  57.     unsigned char code = data & 0xff;
  58.  
  59.     tile_info.flags = TILE_FLIPXY(code & 0x03);
  60.  
  61.     SET_TILE_INFO(1, (code >> 2) + ((0x30 + (attr & 0x0f)) << 6), (attr & 0xf0) >> 4);
  62. }
  63.  
  64. /***************************************************************************
  65.  
  66.     Memory Handlers
  67.  
  68. ***************************************************************************/
  69.  
  70. READ_HANDLER( splash_vram_r )
  71. {
  72.     return READ_WORD(&splash_videoram[offset]);
  73. }
  74.  
  75. WRITE_HANDLER( splash_vram_w )
  76. {
  77.     COMBINE_WORD_MEM(&splash_videoram[offset],data);
  78.     if (offset < 0x1000){    /* Screen 0 */
  79.         tilemap_mark_tile_dirty(screen0,offset/2);
  80.     }
  81.     else{    /* Screen 1 */
  82.         offset -= 0x1000;
  83.         tilemap_mark_tile_dirty(screen1,offset/2);
  84.     }
  85. }
  86.  
  87. READ_HANDLER( splash_pixelram_r )
  88. {
  89.     return READ_WORD(&splash_pixelram[offset]);
  90. }
  91.  
  92. WRITE_HANDLER( splash_pixelram_w )
  93. {
  94.     int sx,sy,color;
  95.  
  96.     COMBINE_WORD_MEM(&splash_pixelram[offset],data);
  97.  
  98.     sx = (offset >> 1) & 0x1ff;    //(offset/2) % 512;
  99.     sy = (offset >> 10);        //(offset/2) / 512;
  100.  
  101.     color = READ_WORD(&splash_pixelram[offset]);
  102.  
  103.     plot_pixel(screen2, sx-9, sy, Machine->pens[0x300 + (color & 0xff)]);
  104. }
  105.  
  106. /***************************************************************************
  107.  
  108.     Start the video hardware emulation.
  109.  
  110. ***************************************************************************/
  111.  
  112. int splash_vh_start(void)
  113. {
  114.     screen0 = tilemap_create(get_tile_info_screen0,tilemap_scan_rows,TILEMAP_TRANSPARENT, 8, 8,64,32);
  115.     screen1 = tilemap_create(get_tile_info_screen1,tilemap_scan_rows,TILEMAP_TRANSPARENT,16,16,32,32);
  116.     screen2 = osd_create_bitmap (512, 256);
  117.  
  118.     if (!screen0 || !screen1 || !screen2)
  119.         return 1;
  120.  
  121.     screen0->transparent_pen = 0;
  122.     screen1->transparent_pen = 0;
  123.  
  124.     tilemap_set_scrollx(screen0, 0, 4);
  125.  
  126.     return 0;
  127. }
  128.  
  129.  
  130. /***************************************************************************
  131.  
  132.     Display Refresh
  133.  
  134. ***************************************************************************/
  135.  
  136. /*
  137.  * Sprite Format
  138.  * -------------
  139.  *
  140.  * Byte | Bit(s)   | Description
  141.  * -----+-76543210-+--------------------------
  142.  *   0  | xxxxxxxx | sprite code (low 8 bits)
  143.  *   2  | xxxxxxxx | y position
  144.  *   4  | xxxxxxxx | x position (low 8 bits)
  145.  *   6  | x------- | flip y
  146.  *   6  | -x------ | flip x
  147.  *   6  | --xx---- | unknown
  148.  *   6  | ----xxxx | sprite code (high 4 bits)
  149.  * 801    | x------- | x position (high bit)
  150.  * 801    | -xxx---- | unknown
  151.  * 801    | ----xxxx | color
  152. */
  153.  
  154. static void draw_sprites(struct osd_bitmap *bitmap)
  155. {
  156.     int i;
  157.     const struct GfxElement *gfx = Machine->gfx[1];
  158.  
  159.     for (i = 0; i < 0x800; i += 8){
  160.         int sx = READ_WORD(&splash_spriteram[i+4]) & 0xff;                        /* x position */
  161.         int sy = 256 - (READ_WORD(&splash_spriteram[i+2]) & 0xff);                /* y position */
  162.         int attr = READ_WORD(&splash_spriteram[i+6]) & 0xff;                    /* attributes */
  163.         int attr2 = READ_WORD(&splash_spriteram[i+0x800]) >> 8;                /* attributes 2 */
  164.         int number = (READ_WORD(&splash_spriteram[i]) & 0xff) + (attr & 0xf)*256;/* sprite number */
  165.  
  166.         if (attr2 & 0x80) sx += 256;
  167.  
  168.         drawgfx(bitmap,gfx,
  169.             number,
  170.             0x10 + (attr2 & 0x0f),
  171.             attr & 0x40, attr & 0x80,
  172.             sx-8,sy-16,
  173.             &Machine->drv->visible_area,
  174.             TRANSPARENCY_PEN,0);
  175.     }
  176. }
  177.  
  178. void splash_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  179. {
  180.     /* set scroll registers */
  181.     tilemap_set_scrolly(screen0, 0, READ_WORD(&splash_vregs[0]));
  182.     tilemap_set_scrolly(screen1, 0, READ_WORD(&splash_vregs[2]));
  183.  
  184.     tilemap_update(ALL_TILEMAPS);
  185.  
  186.     if (palette_recalc())
  187.         tilemap_mark_all_pixels_dirty(ALL_TILEMAPS);
  188.  
  189.     tilemap_render(ALL_TILEMAPS);
  190.  
  191.     copybitmap(bitmap,screen2,0,0,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  192.  
  193.     tilemap_draw(bitmap,screen1,0);
  194.     draw_sprites(bitmap);
  195.     tilemap_draw(bitmap,screen0,0);
  196. }
  197.